package cn.easy.rpc.proxy;

import cn.easy.rpc.annotations.RpcReference;
import org.springframework.cglib.proxy.Enhancer;

/**
 * @author zwb
 * @create 2020-09-18 21:57
 **/
public class RpcProxy {
    public static <T> T create(T target, RpcReference rpcReference) {
        final Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(target.getClass());
        enhancer.setCallback(new RpcInvokeInterceptor(rpcReference));
        return (T) enhancer.create();
    }

    public static <T> T create(Class<T> tClass, RpcReference rpcReference) {
        final Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(tClass);
        enhancer.setCallback(new RpcInvokeInterceptor(rpcReference));
        return (T) enhancer.create();
    }
}
